home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / PInterfaces / MixedMode.p < prev    next >
Encoding:
Text File  |  1996-02-23  |  11.2 KB  |  358 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        MixedMode.p
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1.2 on ETO #20
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. }
  19.  
  20. {$IFC UNDEFINED UsingIncludes}
  21. {$SETC UsingIncludes := 0}
  22. {$ENDC}
  23.  
  24. {$IFC NOT UsingIncludes}
  25.  UNIT MixedMode;
  26.  INTERFACE
  27. {$ENDC}
  28.  
  29. {$IFC UNDEFINED __MIXEDMODE__}
  30. {$SETC __MIXEDMODE__ := 1}
  31.  
  32. {$I+}
  33. {$SETC MixedModeIncludes := UsingIncludes}
  34. {$SETC UsingIncludes := 1}
  35.  
  36.  
  37. {$IFC UNDEFINED __TYPES__}
  38. {$I Types.p}
  39. {$ENDC}
  40. {    ConditionalMacros.p                                            }
  41.  
  42. {$PUSH}
  43. {$ALIGN MAC68K}
  44. {$LibExport+}
  45.  
  46. CONST
  47.     kRoutineDescriptorVersion    = 7;
  48.  
  49. { MixedModeMagic Magic Cookie/Trap number }
  50.     _MixedModeMagic                = $AAFE;
  51.  
  52. { Calling Conventions }
  53.     
  54. TYPE
  55.     CallingConventionType = INTEGER;
  56.  
  57.  
  58. CONST
  59.     kPascalStackBased            = 0;
  60.     kCStackBased                = 1;
  61.     kRegisterBased                = 2;
  62.     kD0DispatchedPascalStackBased = 8;
  63.     kD1DispatchedPascalStackBased = 12;
  64.     kD0DispatchedCStackBased    = 9;
  65.     kStackDispatchedPascalStackBased = 14;
  66.     kThinkCStackBased            = 5;
  67.  
  68. { ISA Types }
  69.     
  70. TYPE
  71.     ISAType = SInt8;
  72.  
  73.  
  74. CONST
  75.     kM68kISA                    = 0;
  76.     kPowerPCISA                    = 1;
  77.  
  78. { RTA Types }
  79.     
  80. TYPE
  81.     RTAType = SInt8;
  82.  
  83.  
  84. CONST
  85.     kOld68kRTA                    = 0+(0 * (2**(4)));
  86.     kPowerPCRTA                    = 0+(0 * (2**(4)));
  87.     kCFM68kRTA                    = 0+(1 * (2**(4)));
  88.  
  89. {$IFC GENERATINGPOWERPC }
  90.     GetCurrentISA                = kPowerPCISA;
  91.     GetCurrentRTA                = kPowerPCRTA;
  92.  
  93. {$ELSEC}
  94. {$IFC GENERATINGCFM }
  95.     GetCurrentISA                = kM68kISA;
  96.     GetCurrentRTA                = kCFM68kRTA;
  97.  
  98. {$ELSEC}
  99.     GetCurrentISA                = kM68kISA;
  100.     GetCurrentRTA                = kOld68kRTA;
  101.  
  102. {$ENDC}
  103. {$ENDC}
  104.     GetCurrentArchitecture        = 0+(GetCurrentISA + GetCurrentRTA);
  105.  
  106.     kRegisterD0                    = 0;
  107.     kRegisterD1                    = 1;
  108.     kRegisterD2                    = 2;
  109.     kRegisterD3                    = 3;
  110.     kRegisterD4                    = 8;
  111.     kRegisterD5                    = 9;
  112.     kRegisterD6                    = 10;
  113.     kRegisterD7                    = 11;
  114.     kRegisterA0                    = 4;
  115.     kRegisterA1                    = 5;
  116.     kRegisterA2                    = 6;
  117.     kRegisterA3                    = 7;
  118.     kRegisterA4                    = 12;
  119.     kRegisterA5                    = 13;
  120.     kRegisterA6                    = 14;
  121. { A7 is the same as the PowerPC SP }
  122.     kCCRegisterCBit                = 16;
  123.     kCCRegisterVBit                = 17;
  124.     kCCRegisterZBit                = 18;
  125.     kCCRegisterNBit                = 19;
  126.     kCCRegisterXBit                = 20;
  127.  
  128.     
  129. TYPE
  130.     registerSelectorType = INTEGER;
  131.  
  132. { SizeCodes we use everywhere }
  133.  
  134. CONST
  135.     kNoByteCode                    = 0;
  136.     kOneByteCode                = 1;
  137.     kTwoByteCode                = 2;
  138.     kFourByteCode                = 3;
  139.  
  140. { Mixed Mode Routine Records }
  141.     
  142. TYPE
  143.     ProcInfoType = LONGINT;
  144.  
  145. { Routine Flag Bits }
  146.     RoutineFlagsType = INTEGER;
  147.  
  148.  
  149. CONST
  150.     kProcDescriptorIsAbsolute    = $00;
  151.     kProcDescriptorIsRelative    = $01;
  152.  
  153.     kFragmentIsPrepared            = $00;
  154.     kFragmentNeedsPreparing        = $02;
  155.  
  156.     kUseCurrentISA                = $00;
  157.     kUseNativeISA                = $04;
  158.  
  159.     kPassSelector                = $0;
  160.     kDontPassSelector            = $08;
  161.  
  162.     kRoutineIsNotDispatchedDefaultRoutine = $0;
  163.     kRoutineIsDispatchedDefaultRoutine = $10;
  164.  
  165.  
  166. TYPE
  167.     RoutineRecord = RECORD
  168.         procInfo:                ProcInfoType;                            { calling conventions }
  169.         reserved1:                SInt8; (* UInt8 *)                        { Must be 0 }
  170.         ISA:                    ISAType;                                { Instruction Set Architecture }
  171.         routineFlags:            RoutineFlagsType;                        { Flags for each routine }
  172.         procDescriptor:            ProcPtr;                                { Where is the thing we’re calling? }
  173.         reserved2:                UInt32;                                    { Must be 0 }
  174.         selector:                UInt32;                                    { For dispatched routines, the selector }
  175.     END;
  176.  
  177.     RoutineRecordPtr = ^RoutineRecord;
  178.     RoutineRecordHandle = ^RoutineRecordPtr;
  179.  
  180. { Mixed Mode Routine Descriptors }
  181. { Definitions of the Routine Descriptor Flag Bits }
  182.     RDFlagsType = UInt8;
  183.  
  184.  
  185. CONST
  186.     kSelectorsAreNotIndexable    = $00;
  187.     kSelectorsAreIndexable        = $01;
  188.  
  189. { Routine Descriptor Structure }
  190.  
  191. TYPE
  192.     RoutineDescriptor = PACKED RECORD
  193.         goMixedModeTrap:        UInt16;                                    { Our A-Trap }
  194.         version:                SInt8;                                    { Current Routine Descriptor version }
  195.         routineDescriptorFlags:    RDFlagsType;                            { Routine Descriptor Flags }
  196.         reserved1:                UInt32;                                    { Unused, must be zero }
  197.         reserved2:                UInt8;                                    { Unused, must be zero }
  198.         selectorInfo:            UInt8;                                    { If a dispatched routine, calling convention, else 0 }
  199.         routineCount:            UInt16;                                    { Number of routines in this RD }
  200.         routineRecords:            ARRAY [0..0] OF RoutineRecord;            { The individual routines }
  201.     END;
  202.  
  203.     RoutineDescriptorPtr = ^RoutineDescriptor;
  204.     RoutineDescriptorHandle = ^RoutineDescriptorPtr;
  205.  
  206.  
  207. CONST
  208. { Calling Convention Offsets }
  209.     kCallingConventionWidth        = 4;
  210.     kCallingConventionPhase        = 0;
  211.     kCallingConventionMask        = $F;
  212. { Result Offsets }
  213.     kResultSizeWidth            = 2;
  214.     kResultSizePhase            = kCallingConventionWidth;
  215.     kResultSizeMask                = $30;
  216. { Parameter offsets & widths }
  217.     kStackParameterWidth        = 2;
  218.     kStackParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth);
  219.     kStackParameterMask            = $FFFFFFC0;
  220. { Register Result Location offsets & widths }
  221.     kRegisterResultLocationWidth = 5;
  222.     kRegisterResultLocationPhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  223. { Register Parameter offsets & widths }
  224.     kRegisterParameterWidth        = 5;
  225.     kRegisterParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth);
  226.     kRegisterParameterMask        = $7FFFF800;
  227.     kRegisterParameterSizePhase    = 0;
  228.     kRegisterParameterSizeWidth    = 2;
  229.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth;
  230.     kRegisterParameterWhichWidth = 3;
  231. { Dispatched Stack Routine Selector offsets & widths }
  232.     kDispatchedSelectorSizeWidth = 2;
  233.     kDispatchedSelectorSizePhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  234. { Dispatched Stack Routine Parameter offsets }
  235.     kDispatchedParameterPhase    = 0+(kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth);
  236. { Special Case offsets & widths }
  237.     kSpecialCaseSelectorWidth    = 6;
  238.     kSpecialCaseSelectorPhase    = kCallingConventionWidth;
  239.     kSpecialCaseSelectorMask    = $3F0;
  240. { Component Manager Special Case offsets & widths }
  241.     kComponentMgrResultSizeWidth = 2;
  242.     kComponentMgrResultSizePhase = kCallingConventionWidth + kSpecialCaseSelectorWidth; { 4 + 6 = 10 }
  243.     kComponentMgrParameterWidth    = 2;
  244.     kComponentMgrParameterPhase    = kComponentMgrResultSizePhase + kComponentMgrResultSizeWidth; { 10 + 2 = 12 }
  245.  
  246.     kSpecialCase                = $0000000F;
  247.  
  248. { all of the special cases enumerated.  The selector field is 6 bits wide }
  249.     kSpecialCaseHighHook        = 0;
  250.     kSpecialCaseCaretHook        = 0;                            { same as kSpecialCaseHighHook }
  251.     kSpecialCaseEOLHook            = 1;
  252.     kSpecialCaseWidthHook        = 2;
  253.     kSpecialCaseTextWidthHook    = 2;                            { same as kSpecialCaseWidthHook }
  254.     kSpecialCaseNWidthHook        = 3;
  255.     kSpecialCaseDrawHook        = 4;
  256.     kSpecialCaseHitTestHook        = 5;
  257.     kSpecialCaseTEFindWord        = 6;
  258.     kSpecialCaseProtocolHandler    = 7;
  259.     kSpecialCaseSocketListener    = 8;
  260.     kSpecialCaseTERecalc        = 9;
  261.     kSpecialCaseTEDoText        = 10;
  262.     kSpecialCaseGNEFilterProc    = 11;
  263.     kSpecialCaseMBarHook        = 12;
  264.     kSpecialCaseComponentMgr    = 13;
  265.  
  266. {
  267.     NOTES ON USING New[Fat]RoutineDescriptor[Trap] 
  268.     
  269.     When calling these routine from classic 68k code there are two possible intentions.
  270.  
  271.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  272.     the code is compiled for CFM the functions create routine descriptors that can be used by
  273.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  274.     these functions do nothing so that the code will run on Macintoshes that do not have a
  275.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  276.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  277.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  278.     intended runtime/instruction platform. All without source changes and/or conditional source.
  279.     
  280.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  281.     and is specifically trying to call code of another architecture using mixed mode. Since the
  282.     routines were designed with classic <-> CFM source compatibility in mind this second case
  283.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  284.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  285.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  286.     from CFM code will result in runtime failure because no shared library implements or exports
  287.     the functions.
  288.     
  289.  
  290.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  291.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  292.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  293.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  294.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  295.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  296.     
  297.     By definition fat routine descriptors are only constructed by code that is aware of the 
  298.     architecture it is executing as and that another architecture exists. Source compatibility
  299.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  300.     is not available when building pure classic code.
  301.     
  302.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  303.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  304.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  305.     and classic    routine.
  306. }    
  307.  
  308. {$IFC GENERATINGCFM }
  309. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  310. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  311. FUNCTION NewFatRoutineDescriptor(theM68kProc: ProcPtr; thePowerPCProc: ProcPtr; theProcInfo: ProcInfoType): UniversalProcPtr;
  312. {$ELSEC}
  313. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  314.     {$IFC NOT GENERATINGCFM}
  315.     INLINE $5C4F, $2E9F;
  316.     {$ENDC}
  317. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  318.     {$IFC NOT GENERATINGCFM}
  319.     INLINE $584F;
  320.     {$ENDC}
  321. {  Note that the call to NewFatRoutineDescriptor is undefined when GENERATINGCFM is false.  }
  322.  
  323. FUNCTION NewRoutineDescriptorTrap(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  324.     {$IFC NOT GENERATINGCFM}
  325.     INLINE $7000, $AA59;
  326.     {$ENDC}
  327. PROCEDURE DisposeRoutineDescriptorTrap(theProcPtr: UniversalProcPtr);
  328.     {$IFC NOT GENERATINGCFM}
  329.     INLINE $7001, $AA59;
  330.     {$ENDC}
  331. FUNCTION NewFatRoutineDescriptorTrap(theM68kProc: ProcPtr; thePowerPCProc: ProcPtr; theProcInfo: ProcInfoType): UniversalProcPtr;
  332.     {$IFC NOT GENERATINGCFM}
  333.     INLINE $7002, $AA59;
  334.     {$ENDC}
  335. {$ENDC}
  336.  
  337. {$IFC GENERATINGCFM }
  338. {
  339.  CallUniversalProc is only implemented in shared libraries on 68k and PowerPC, it is now
  340.  conditionalize with GENERATINGCFM.  This will catch accidental calls from classic 68K code
  341.  that previously only showed up as linker errors.
  342. }
  343. FUNCTION CallUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  344. FUNCTION CallOSTrapUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  345. {$ENDC}
  346.  
  347.  
  348. {$ALIGN RESET}
  349. {$POP}
  350.  
  351. {$SETC UsingIncludes := MixedModeIncludes}
  352.  
  353. {$ENDC} {__MIXEDMODE__}
  354.  
  355. {$IFC NOT UsingIncludes}
  356.  END.
  357. {$ENDC}
  358.